%matplotlib inline
import pandas as pd
import matplotlib.pyplot as plt
= pd.read_csv('percent-bachelors-degrees-women-usa.csv')
women_degrees = (0/255,107/255,164/255)
cb_dark_blue = (255/255, 128/255, 14/255)
cb_orange = ['Engineering', 'Computer Science', 'Psychology', 'Biology', 'Physical Sciences', 'Math and Statistics']
stem_cats
= plt.figure(figsize=(18, 3))
fig
for sp in range(0,6):
= fig.add_subplot(1,6,sp+1)
ax 'Year'], women_degrees[stem_cats[sp]], c=cb_dark_blue, label='Women', linewidth=3)
ax.plot(women_degrees['Year'], 100-women_degrees[stem_cats[sp]], c=cb_orange, label='Men', linewidth=3)
ax.plot(women_degrees["right"].set_visible(False)
ax.spines["left"].set_visible(False)
ax.spines["top"].set_visible(False)
ax.spines["bottom"].set_visible(False)
ax.spines[1968, 2011)
ax.set_xlim(0,100)
ax.set_ylim(
ax.set_title(stem_cats[sp])="off", top="off", left="off", right="off")
ax.tick_params(bottom
if sp == 0:
2005, 87, 'Men')
ax.text(2002, 8, 'Women')
ax.text(elif sp == 5:
2005, 62, 'Men')
ax.text(2001, 35, 'Women')
ax.text( plt.show()
Comparing across all degrees
There are seventeen degrees, to generate line chart, we’ll use a subplot grid layout of 6 rows by 3 columns.
= ['Psychology', 'Biology', 'Math and Statistics', 'Physical Sciences', 'Computer Science', 'Engineering']
stem_cats = ['Foreign Languages', 'English', 'Communications and Journalism', 'Art and Performance', 'Social Sciences and History']
lib_arts_cats = ['Health Professions', 'Public Administration', 'Education', 'Agriculture','Business', 'Architecture'] other_cats
= plt.figure(figsize=(16,20))
fig
for sp in range(0,18,3):
= int(sp/3)
cat_index = fig.add_subplot(6,3,sp+1)
ax 'Year'], women_degrees[stem_cats[cat_index]], c=cb_dark_blue, label='Women', linewidth=3)
ax.plot(women_degrees['Year'], 100-women_degrees[stem_cats[cat_index]], c=cb_orange, label='Men', linewidth=3)
ax.plot(women_degrees[for key,spine in ax.spines.items():
False)
spine.set_visible(1968, 2011)
ax.set_xlim(0,100)
ax.set_ylim(
ax.set_title(stem_cats[cat_index])="off", top="off", left="off", right="off")
ax.tick_params(bottom0,100])
ax.set_yticks([50, c=(171/255, 171/255, 171/255), alpha=0.3)
ax.axhline(
if cat_index == 0:
2003, 85, 'Women')
ax.text(2005, 10, 'Men')
ax.text(elif cat_index == 5:
2005, 87, 'Men')
ax.text(2003, 7, 'Women')
ax.text(='on')
ax.tick_params(labelbottom
for sp in range(1,16,3):
= int((sp-1)/3)
cat_index = fig.add_subplot(6,3,sp+1)
ax 'Year'], women_degrees[lib_arts_cats[cat_index]], c=cb_dark_blue, label='Women', linewidth=3)
ax.plot(women_degrees['Year'], 100-women_degrees[lib_arts_cats[cat_index]], c=cb_orange, label='Men', linewidth=3)
ax.plot(women_degrees[for key,spine in ax.spines.items():
False)
spine.set_visible(1968, 2011)
ax.set_xlim(0,100)
ax.set_ylim(
ax.set_title(lib_arts_cats[cat_index])="off", top="off", left="off", right="off")
ax.tick_params(bottom0,100])
ax.set_yticks([50, c=(171/255, 171/255, 171/255), alpha=0.3)
ax.axhline(
if cat_index == 0:
2003, 78, 'Women')
ax.text(2005, 18, 'Men')
ax.text(elif cat_index == 4:
='on')
ax.tick_params(labelbottom
for sp in range(2,20,3):
= int((sp-2)/3)
cat_index = fig.add_subplot(6,3,sp+1)
ax 'Year'], women_degrees[other_cats[cat_index]], c=cb_dark_blue, label='Women', linewidth=3)
ax.plot(women_degrees['Year'], 100-women_degrees[other_cats[cat_index]], c=cb_orange, label='Men', linewidth=3)
ax.plot(women_degrees[for key,spine in ax.spines.items():
False)
spine.set_visible(1968, 2011)
ax.set_xlim(0,100)
ax.set_ylim(
ax.set_title(other_cats[cat_index])="off", top="off", left="off", right="off")
ax.tick_params(bottom0,100])
ax.set_yticks([50, c=(171/255, 171/255, 171/255), alpha=0.3)
ax.axhline(
if cat_index == 0:
2003, 90, 'Women')
ax.text(2005, 5, 'Men')
ax.text(elif cat_index == 5:
2005, 62, 'Men')
ax.text(2003, 30, 'Women')
ax.text(='on')
ax.tick_params(labelbottom
plt.show()